package com.coderman.daotest.csdn.service;

import com.coderman.daoclient.dao.IDao;
import com.coderman.daoclient.dao.impl.IDaoImpl;
import com.coderman.daotest.csdn.bean.CsdnUserEntity;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by ${fanchunshuai} on 2017-8-10.
 *
 * @version: V1.0
 * @Desc:
 * @Copyright (c) 2017 58到家-版权所有
 */
public class InsertUserService {
    static IDao<CsdnUserEntity,Long> dao = new IDaoImpl<CsdnUserEntity,Long>();

    public static void main(String[] args) throws Exception {

        Map<String,String> map = dao.getMap(CsdnUserEntity.class,"nick_name","id");
        System.out.println(map.size());

        File file = new File("E:\\spiderFile\\csdnUserLink2.txt");


        try {
            List<String> list = FileUtils.readLines(file,"utf-8");
            int i = 0;
            for (String urls : list){
                String [] urlArray = urls.split(",");
                for (String url : urlArray) {
                    if (StringUtils.isBlank(url)) {
                        continue;
                    }
                    i++;
                    String nick_name = url.split("/")[3];
                    if(map.containsKey(nick_name)){
                        continue;
                    }
                    CsdnUserEntity csdnUserEntity = new CsdnUserEntity();
                    csdnUserEntity.setNickName(nick_name);
                    dao.insertEntity(csdnUserEntity);
                    /* String sql = " insert into csdn_user (nick_name) values('"+nick_name+"');\n";*/
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
